class Company < ActiveRecord::Base

  hobo_model
  
  acts_as_ferret :fields => [:name, :abn, :street_address, :postcode, :telephone, :email, :city, :country]

  acts_as_reportable #:only => ['name']
  
  set_search_columns :name, :abn, :street_address, :postcode, :telephone, :email, :city, :country

  has_many  :documents
  has_many  :people
  
  def self.full_text_search(q, options = {})
   return nil if q.nil? or q==""
   default_options = {:limit => 10, :page => 1}
   options = default_options.merge options
   
   # get the offset based on what page we're on
   options[:offset] = options[:limit] * (options.delete(:page).to_i-1)  
   
   # now do the query with our options
   results = self.find_by_contents(q, options)
   return [results.total_hits, results]
end

  # --- Hobo Permissions --- #

  def creatable_by?(creator)
    not creator.guest?
  end

  def updatable_by?(updater, new)
    not updater.guest?
  end

  def deletable_by?(deleter)
    false
  end

  def viewable_by?(viewer, field)
    true
  end

end
